from pykafka import KafkaClient

client = KafkaClient(hosts="127.0.0.1:9092")

topic = client.topics[b'test']


with topic.get_sync_producer() as producer:
    for i in range(4):
        msg = 'test message ' + str(i ** 2)
        producer.produce(str.encode(msg))